#!/usr/bin/env python
# -*- coding:utf-8 -*-
#发布订阅
#fanout ==>广播
# ######################### 发布者 #########################
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.136.8'))
channel = connection.channel()

channel.exchange_declare(exchange='channel_name',type='fanout')

message = ' '.join(sys.argv[1:]) or "info: Hello World!"
channel.basic_publish(exchange='channel_name',  #自命名exchange
                      routing_key='',
                      body=message)
print(" [x] Sent %r" % message)
connection.close()